package com.example.wasaimovie.Service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.wasaimovie.Mapper.FilmMapper;
import com.example.wasaimovie.Model.entity.Film;
import com.example.wasaimovie.Service.FilmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class FilmServiceImpl extends ServiceImpl<FilmMapper, Film> implements FilmService {
    @Autowired
    FilmService service;

    @Value("${movie.image.url.path}")
    String url;

    /**
     * 查询热门电影列表
     * @param number 查询数量
     * @return 返回热门电影信息
     */
    @Override
    public List<Film> selectByHot(int number) {
        QueryWrapper<Film> qw = new QueryWrapper<>();
        qw.orderByDesc("hot");
        List<Film> list = service.list(qw);
        List<Film> films = null;
        if (list.size() >= number){
            films = list.subList(0, number);
        } else {
            films = list.subList(0, list.size());
        }
        for (int i = 0; i < films.size(); i++){
            films.get(i).setCover(url + films.get(i).getCover());
        }
        return films;
    }
}
